/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spring.DAO;

import com.spring.entidades.Cliente;
import java.util.List;
import javax.swing.JOptionPane;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author jerick
 */
@Repository
public class ClienteDAO  extends HibernateDaoSupport{
    
    @Autowired

    public ClienteDAO(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }
    public List<Cliente> getListarCliente(){
        return getHibernateTemplate().find("select c from Cliente c");
    }
    public List<Cliente> getlistabuscar_cliente(String emp)
     {
         //JOptionPane.showMessageDialog(null, emp);
         return getHibernateTemplate().findByNamedParam("select c from Cliente c where c.ruc=:param", "param", emp);//en jpql
     }
    
    public boolean insertarCliente(Cliente emp){
         boolean b=false;
     try{
         getHibernateTemplate().saveOrUpdate(emp);
         b=true;
     }
     catch(Exception e)
     {
         JOptionPane.showMessageDialog(null, e.getMessage());
     }
         return b;
     }
     
      public boolean eliminarCliente(String codigo)
     {
         boolean b=false;
         try{
             Cliente t=getHibernateTemplate().get(Cliente.class, codigo);
             getHibernateTemplate().delete(t);
             b=true;
             
         }
         catch (Exception e){
             b=false;
             
         }
         return b;
     }

    
}
